package com.remenote.remenoteback.context.interceptor;

import com.remenote.remenoteback.entity.exception.NoAuthorityException;
import com.remenote.remenoteback.entity.exception.PromptException;
import com.remenote.remenoteback.entity.resp.ServerResponse;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @BelongsProject: remenote-back
 * @BelongsPackage: com.remenote.remenoteback.context.interceptor
 * @Author: 23392
 * @CreateTime: 2024-03-18  14:27
 * @Description: TODO
 * @Version: 1.0
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    public ServerResponse handleException(Exception e){
        return  ServerResponse.buildErrorResponse("系统异常"+e.getMessage());
    }
    @ExceptionHandler(NullPointerException.class)
    public ServerResponse handleNullException(Exception e){
        e.printStackTrace();
        return ServerResponse.buildErrorResponse("参数为空");
    }
    @ExceptionHandler(IllegalArgumentException.class)
    public ServerResponse handleIllegalArgs(Exception e){
        return ServerResponse.buildErrorResponse("非法参数");
    }
    @ExceptionHandler(NoAuthorityException.class)
    public ServerResponse handleNoAuthority(Exception e){
        return ServerResponse.buildErrorResponse(ServerResponse.ResponseCode.NEED_LOGIN.getCode(),"No authority");
    }
    @ExceptionHandler(PromptException.class)
    public ServerResponse handlePromptException(Exception e){
        return ServerResponse.buildErrorResponse(e.getMessage());
    }
}
